<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>54数组扁平化、去重与排序</title>
</head>
<body>
<script>
  let arr = [9, 20, 4, [1, 2, 3, 4], [2, 3, 4, [1, 2, 3, [1, 2, 3]], 5], [1, 2, 3, 4], [3, 4, 5, 9]]

  console.log(flatten(arr));

  function flatten(arr) {
    let _arr = arr || [],
      fArr = [],
      len = _arr.length,
      item;
    for (let i = 0; i < len; i++) {
      item = _arr[i]
      if (_isArr(item)) {
        fArr = fArr.concat(flatten(item))
      } else {
        fArr.push(item)
      }
    }

    return fArr = Array.from(new Set(fArr)).sort((a, b) => {
      return a - b
    })

    function _isArr(item) {
      return {}.toString.call(item) === '[object Array]'
    }
  }
</script>
</body>
</html>